package index;

import java.util.Map;
import java.util.TreeMap;
import java.util.HashMap;

public class BlockIndex {
	private Map<Integer,String[]> blockIndex = new TreeMap<Integer,String[]>();
	
	private Map<String,String> indexedData = new HashMap<String,String>();
	
	public void init(){
		indexedData.put("1", "one");
		indexedData.put("2", "two");
		indexedData.put("3", "three");
		indexedData.put("4", "four");
		indexedData.put("5", "five");
		indexedData.put("6", "six");
		indexedData.put("7", "seven");
		indexedData.put("8", "eight");
		indexedData.put("9", "nine");
		indexedData.put("10", "ten");
		createIndex();
	}
	
	public void createIndex(){
		blockIndex.put(4, new String[]{"3","1","2","4"});
		blockIndex.put(7, new String[]{"7","6","5"});
		blockIndex.put(10, new String[]{"8","10","9"});
	}
	
	public String getData(Integer index){
		Integer blockKey = 0;
		Integer[] bKey = new Integer[blockIndex.keySet().size()];
		int count=0;
		for(Integer key:blockIndex.keySet()){
			bKey[count] = key;
			count++;
		}
		for(int i=1;i<bKey.length;i++){
			if(bKey[i-1]<index&&index<bKey[i]){
				blockKey = bKey[i];
			}else if(index==bKey[i-1]){
				blockKey = bKey[i-1];
			}else if(index==bKey[i]){
				blockKey = bKey[i];
			}
		}
		String[] blockIndexValue = blockIndex.get(blockKey);
		for(int i=0;i<blockIndexValue.length;i++){
			if(index == Integer.valueOf(blockIndexValue[i])){
				return indexedData.get(String.valueOf(blockIndexValue[i]));
			}
		}
		return null;
	}
	
	public static void main(String[] args) throws Exception{
		BlockIndex bi = new BlockIndex();
		bi.init();
		System.out.println(bi.getData(6));
	}
}
